(旧Siv3D) ピクセルシェーダでテクスチャを白く点滅させる
https://gyazo.com/7878f59b5180fdfbbf30d4431e12e389
code:s3dkun_blink.cpp
struct CB1
{
float strength;
float reserved1;
float reserved2;
float reserved3;
};
void Main()
{
const String s3dkunBase64Image = L"iVBORw0KGgoAAAANSUhEUgAAADAAAAAgCAMAAABjCgsuAAAARVBMVEUAAACfz7c/n29/v5//x5NwcHDf7+f/ll9QUFC/f/+/38+QkJB/AADPj0/fv//Pn///jIz+AAD////g4ODQ0NDAwMDAAADbxb57AAAAAXRSTlMAQObYZgAAAVlJREFUOMu1kNuWwiAMRRMChulFrbf//9Q54WLBocunOUtpu3eSQuk/wsjEPOAjwSmn0+nD8FhklIz9Gj4WeQiSb6aW96LnSJ00Jz4Slc/BxFw2EMgiyEgw+DwHh0fhEkpxbigEPEAEqDevHWNhHYaFxVmE6VBUDpCW++P+wB2VHAkgxD1vi95VbwvTF5GH6G17KbK9mBohAwGOev9cFo8sC7UNBwLYX6+gdqFdyFg4xKdsm/cA30XOumKhjo+FHUKwyCrAbcYCuERFOiOt+KznaWKk63CdeGOcSVzik3HfnaGKvkExinNE2wbMckU0XLVtWLU5A2bJ3waH7A3tmYPq3qANdyli37D/SGPBbOKnpH3BWAAbP58vF/uHEOr8XuRiklK/pj2q1xCjmV6oat0MV+wTsfrY13uYtCQMChxj3UetD1kQRQ1w0dedZkrvBirzS7kZpKzH+QXriRABIX6TjgAAAABJRU5ErkJggg==";
const Texture texture(Base64::Decode(s3dkunBase64Image));
PixelShader ps(L"white.hlsl");
ConstantBuffer<CB1> cb1;
Graphics::SetBackground(Color(40));
Graphics2D::SetSamplerState(SamplerState::ClampPoint);
Window::Resize(800, 600);
while (System::Update())
{
const int F = System::FrameCount();
Graphics2D::BeginPS(ps);
cb1->strength = Saturate(sin(F / 20.0) * 0.5 + 0.5);
Graphics2D::SetConstant(ShaderStage::Pixel, 1, cb1);
texture(((F / 25) % 2) * texture.width / 2, 0, texture.width / 2, texture.height)
.scale(3)
.draw(100, 100);
Graphics2D::EndPS();
ClearPrint();
Println(L"strength = ", cb1->strength);
}
}
code: white.hlsl
Texture2D texture0 : register( t0 );
SamplerState sampler0 : register( s0 );
cbuffer CB : register(b1)
{
float strength;
float reserved1;
float reserved2;
float reserved3;
};
struct VS_OUTPUT
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float4 color : COLOR0;
};
float4 PS(VS_OUTPUT input) : SV_Target
{
float4 srcColor = texture0.Sample(sampler0, input.tex);
srcColor.rgb += (float3(1.0, 1.0, 1.0) - srcColor.rgb) * strength;
return srcColor * input.color;
}